﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;

public partial class UserControl_Witness : System.Web.UI.UserControl
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            FillWitness();
        }
    }

    private void FillWitness()
    {
        Dictionary<string, string> conditions = new Dictionary<string, string>();
        conditions.Add("ParentNodeId", "8");
        conditions.Add("Flag", "1");
        conditions.Add("PageIndex", "0");
        conditions.Add("PageSize", "4");
        RepeaterWitness.DataSource = m_PostService.GetPostList(conditions);
        RepeaterWitness.DataBind();
    }

    protected void RepeaterWitness_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            Control ctrl = e.Item;
            PostVO postVO = (PostVO)e.Item.DataItem;
            postVO = m_PostService.GetPostByIdNoLazy(postVO.PostId);

            //標題
            int customField1Length = 18;
            if (!string.IsNullOrEmpty(postVO.CustomField1))
            {
                string title = postVO.CustomField1;
                if (title.Length > customField1Length)
                {
                    title = title.Substring(0, customField1Length) + "...";
                }

                UIHelper.SetLiteralText(ctrl, "ltlCustomField1", title);
            }

            UIHelper.SetLiteralText(ctrl, "ltlNodeName", postVO.Node.Name);
        }
    }
}